//
//  KYZXWebMoreView.m
//  KuYouZiXun
//
//  Created by lanou on 15/9/7.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "KYZXWebMoreView.h"

#import "KYZXUserInfo.h"

@interface KYZXWebMoreView ()

@property (weak, nonatomic) IBOutlet UISwitch *changeColorSwitch;

@property (weak, nonatomic) IBOutlet UISegmentedControl *changeFontSizeSegment;

@property (weak, nonatomic) IBOutlet UISwitch *changeImagePlaySwitch;

@end

@implementation KYZXWebMoreView

- (void)dealloc
{
    [[KYZXUserInfo standardKYZXUserInfo]removeObserver:self];
}

+(KYZXWebMoreView *)instanceView
{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"KYZXWebMoreView" owner:nil options:nil];
    return [nibView objectAtIndex:0];
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if(self)
    {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doTap)];
        [self addGestureRecognizer:tap];
        [[KYZXUserInfo standardKYZXUserInfo] addObserver:self];
    }
    return self;
}


- (void)getUserInfo
{
    NSString *userColorInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"配色方案"];
    if([userColorInfo isEqualToString:@"日间模式"] || userColorInfo == nil){
        _changeColorSwitch.on = NO;
    }
    else{
        _changeColorSwitch.on = YES;
    }
    NSString *userImagePlayInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"图片方案"];
    if([userImagePlayInfo isEqualToString:@"有图模式"] || userImagePlayInfo == nil){
        _changeImagePlaySwitch.on = NO;
    }
    else{
        _changeImagePlaySwitch.on = YES;
    }
}


- (void)doTap
{
    self.hidden = YES;
}

- (IBAction)changeColor:(id)sender
{
    UISwitch *sender1 = (UISwitch *)sender;
    if (sender1.on) {
        [[NSUserDefaults standardUserDefaults] setObject:@"夜间模式" forKey:@"配色方案"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeColor" object:nil userInfo:@{@"配色方案":@"夜间模式"}];
    }
    else{
        [[NSUserDefaults standardUserDefaults] setObject:@"日间模式" forKey:@"配色方案"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeColor" object:nil userInfo:@{@"配色方案":@"日间模式"}];
    }
}


- (IBAction)changeFontSize:(id)sender {
}


- (IBAction)changeImagePlay:(id)sender
{
    UISwitch *sender1 = (UISwitch *)sender;
    if (sender1.on) {
        [[NSUserDefaults standardUserDefaults] setObject:@"无图模式" forKey:@"图片方案"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeImagePlay" object:nil userInfo:@{@"图片方案":@"无图模式"}];
        
    }
    else{
        [[NSUserDefaults standardUserDefaults] setObject:@"有图模式" forKey:@"图片方案"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeImagePlay" object:nil userInfo:@{@"图片方案":@"有图模式"}];
    }
}

- (IBAction)refreshView:(id)sender {
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    [self getUserInfo];
}
@end
